//
//  TabBarViewController.m
//  fenlegu
//
//  Created by lazy on 3/28/13.
//  Copyright (c) 2013 lazy. All rights reserved.
//

#import "TabBarViewController.h"

#import "TBTabButton.h"
#import "TBViewController.h"
#import "Home.h"
#import "Weiba.h"
#import "Game.h"
#import "Album.h"
#import "Person.h"


@interface TabBarViewController ()

@end

@implementation TabBarViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
    Weiba *weiba = [[Weiba alloc] init];
    Game *game = [[Game alloc] init];
    Home *home = [[Home alloc] init];
    Album *album = [[Album alloc] init];
    Person *person = [[Person alloc] init];
    
	
    UINavigationController *weibaNav=[[UINavigationController alloc] initWithRootViewController:weiba];
    [weiba release];
	
    UINavigationController *gameNav=[[UINavigationController alloc] initWithRootViewController:game];
    [game release];
	
    UINavigationController *homeNav=[[UINavigationController alloc] initWithRootViewController:home];
    [home release];
    
	UINavigationController *albumNav = [[UINavigationController alloc] initWithRootViewController:album];
    [album release];
    
    UINavigationController *personNav = [[UINavigationController alloc] initWithRootViewController:person];
    [person release];
    
//    
//    
//    Weiba *weiba = [[[Weiba alloc] init] autorelease];
//    Game *game = [[[Game alloc] init] autorelease];
//    Home *home = [[[Home alloc] init] autorelease];
//    Album *album = [[[Album alloc] init] autorelease];
//    Person *person = [[[Person alloc] init] autorelease];

    
    TBViewController *vc3 = [[[TBViewController alloc] init] autorelease];
    vc3.view.backgroundColor = [UIColor darkGrayColor];
    
    TBTabButton *weibaTB = [[[TBTabButton alloc] initWithIcon:[UIImage imageNamed:@"weiba"]] autorelease];
    weibaTB.highlightedIcon = [UIImage imageNamed:@"weiba_xz"];
    weibaTB.viewController = weibaNav;
    
    TBTabButton *gameTB = [[[TBTabButton alloc] initWithIcon:[UIImage imageNamed:@"game"]] autorelease];
    gameTB.highlightedIcon = [UIImage imageNamed:@"game_xz"];
    gameTB.viewController = gameNav;
    
    TBTabButton *HomeTB = [[[TBTabButton alloc] initWithIcon:[UIImage imageNamed:@"bottom_logo"]] autorelease];
    HomeTB.highlightedIcon = [UIImage imageNamed:@"bottom_logo"];
    HomeTB.viewController = homeNav;
    
    TBTabButton *albumTB = [[[TBTabButton alloc] initWithIcon:[UIImage imageNamed:@"album"]] autorelease];
    albumTB.highlightedIcon = [UIImage imageNamed:@"album_xz"];
    albumTB.viewController = albumNav;
    
    TBTabButton *personTB = [[[TBTabButton alloc] initWithIcon:[UIImage imageNamed:@"personal"]] autorelease];
    personTB.highlightedIcon = [UIImage imageNamed:@"personal_xz"];
    personTB.viewController = personNav;
    
    NSArray *arr = [NSArray arrayWithObjects:weibaTB, gameTB, HomeTB, albumTB, personTB, nil];
    tabBar = [[TBTabBar alloc] initWithItems:arr];
    tabBar.delegate = self;
    [self.view addSubview:tabBar];
    [tabBar showDefaults];
    
    [weibaNav release];
    [gameNav release];
    [homeNav release];
    [albumNav release];
    [personNav release];
    
}

-(void)switchViewController:(UIViewController *)viewController {
    
    UIView *currentView = [self.view viewWithTag:SELECTED_VIEW_CONTROLLER_TAG];
    [currentView removeFromSuperview];
    
    viewController.view.frame = CGRectMake(0,0,self.view.bounds.size.width, self.view.bounds.size.height-(tabBar.frame.size.height));
    
    viewController.view.tag = SELECTED_VIEW_CONTROLLER_TAG;
    
    [self.view insertSubview:viewController.view belowSubview:tabBar];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


- (void)dealloc
{
    [tabBar release];
    [super dealloc];
}


@end
